

import 'package:web_socket_channel/web_socket_channel.dart';

typedef SocketCallback=void Function(String message);
class WebSocketModel{
  final String wsPath;//websocket 请求地址
  bool bindNotification; //是否需要消息推送
  SocketCallback callback;
  String token;
  int userId;
  WebSocketChannel channel;

  setChannel(WebSocketChannel channel){
    this.channel=channel;
  }

/*
  String getWebSocketPath(){
    String _token = this.token;
    _token=_token !=null ?_token:'';
    _token='Bearer '+_token;
    _token= '?Authorization='+_token;
    _token +=('&userId=1');
    _token+=('&client=APP');
    return wsPath+_token;
  }*/

  String getWebSocketPath(int userId){
    String _token = this.token;
    _token=_token !=null ?_token:'';
    _token='Bearer '+_token;
    _token= '?Authorization='+_token;
    _token +=('&userId='+userId.toString());
    _token+=('&client=APP');
    return wsPath+_token;
  }

  WebSocketModel(this.wsPath,{
    this.bindNotification,
    this.token,
    this.callback,
    this.userId
  })
    {
      if(bindNotification == null){
        bindNotification=true;
      }
    }


}